home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.3d26 source
/
tn3270
/
crcf.c
< prev
next >
Wrap
Text File
|
1991-01-21
|
3KB
|
89 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.3d21, January 17, 1991
* Copyright (c) 1988, 1989, 1990, 1991 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
crcf(str,len,initchk)
char *str;
short len;
unsigned short initchk;
{
static char tabok = 0;
static unsigned short crctab[256];
register short i, table_pos;
register unsigned short result;
if (!tabok) {
gentab(crctab);
tabok = 1;
}
result = initchk;
for (i=0; i < len; i++) {
table_pos = (result ^ str[i]) & 0x00ff;
result >>= 8;
result ^= crctab[table_pos];
}
return(result);
}
gentab(array)
unsigned short array[256];
{
char x, x1, x2, x3, x4, x5, x6, x7, x8;
register short count;
count = 0;
for (x8=0; x8 < 2; x8++)
for (x7=0; x7 < 2; x7++)
for (x6=0; x6 < 2; x6++)
for (x5=0; x5 < 2; x5++)
for (x4=0; x4 < 2; x4++)
for (x3=0; x3 < 2; x3++)
for (x2=0; x2 < 2; x2++)
for (x1=0; x1 < 2; x1++) {
array[count] = 0;
x = x8 ^ x7 ^ x6 ^ x5 ^ x4 ^ x3 ^ x2 ^ x1;
if (x) array[count] += 0x8000;
if (x7 ^ x6 ^ x5 ^ x4 ^ x3 ^ x2 ^ x1) array[count] += 0x4000;
if (x8 ^ x7) array[count] += 0x2000;
if (x7 ^ x6) array[count] += 0x1000;
if (x6 ^ x5) array[count] += 0x0800;
if (x5 ^ x4) array[count] += 0x0400;
if (x4 ^ x3) array[count] += 0x0200;
if (x3 ^ x2) array[count] += 0x0100;
if (x2 ^ x1) array[count] += 0x0080;
if (x1) array[count] += 0x0040;
array[count++] += x;
}
}